import request from '@/utils/request';
// 获取产品列表
export async function getProductPageIndex(data: Center.ProductPrams) {
  return request<Center.ProductList[]>({
    method: 'post',
    url: '/web/getProductPageIndex',
    data,
  });
}
// 获取产品详情计算金额利率
export async function getOrderBeforeInfo(params: { pid: string }) {
  return request<{
    amount: number;
    rate: number;
  }>({
    method: 'get',
    url: '/web/getOrderBeforeInfo',
    params,
  });
}
// 申请订单
export async function handleApplyOrder(data: Center.OrderParams & { apiToken: string }) {
  const { apiToken, ...rest } = data;
  return request<string>({
    method: 'post',
    url: '/web/apply',
    data: rest,
    headers: {
      apiToken,
    },
  });
}
// 获取幂等token
export async function handleGetToken() {
  return request<string>({
    method: 'post',
    url: '/web/token',
  });
}

// 获取预约信息
export async function hanldeViewDetail(params: { orderId: string }) {
  return request<{ address: string; start: string; end: string }>({
    method: 'get',
    url: '/web/InterviewDetail',
    params,
  });
}
// 获取滚动信息
export async function hanldeScrollInfo() {
  return request<string[]>({
    method: 'get',
    url: '/web/scrollInfo',
  });
}
// 修改预约时间
export async function updateInterviewTime(data: { orderId: string; interviewTime: string }) {
  return request<[]>({
    method: 'post',
    url: '/web/updateInterviewTime',
    data,
  });
}
// 获取订单列表
export async function getOrderPage(data: {
  p?: number;
  s?: number;
  status?: number;
  startTime?: number;
  endTime?: number;
}) {
  return request<Center.Data<Center.Record>>({
    method: 'post',
    url: '/web/getOrderPage',
    data,
  });
}
// 获取消息列表
export async function getNotification(params: { p: number; s: number }) {
  return request<Center.Data<Center.MsgList>>({
    method: 'get',
    url: '/web/getNotification',
    params,
  });
}
// 消息已读标识
export async function handleNotification(data: { ids: string[] }) {
  return request<Center.Data<Center.MsgList>>({
    method: 'post',
    url: '/web/handleNotification',
    data,
  });
}
// 跳转三方
export async function handleUrl(params: { pid: string }) {
  return request<string>({
    method: 'get',
    url: '/web/redirect',
    params,
  });
}
// 埋点
export async function handleEvent(tag: string) {
  return tag;
  // return request<[]>({
  //   method: 'post',
  //   url: `/web/event`,
  //   data: { tag },
  // });
}

// 获取新闻
export async function getNewsList(params: { p: number; s: number; type: string }) {
  return request<any>({
    method: 'get',
    url: '/web/getNewsList',
    params,
  });
}
// 获取新闻详情
export async function getNewsDetail(params: { id: string }) {
  return request<any>({
    method: 'get',
    url: '/web/getNewsDetail',
    params,
  });
}

export async function getRebate() {
  return request<Center.RebateList[]>({
    method: 'get',
    url: '/web/getRebate',
  });
}

export async function getFaqList() {
  return request<any>({
    method: 'get',
    url: '/web/getFaqList',
  });
}
export async function getRecruitment() {
  return request<any>({
    method: 'get',
    url: '/web/getRecruitment',
  });
}

export async function getFieldConfig() {
  return request<any>({
    method: 'get',
    url: '/web/getFieldConfig',
  });
}
export async function getProductConfig(params: { pid: string }) {
  return request<{
    productInfo: Center.ProductList;
    emptyField: { key: string; keyDesc: string; positionId: string; keyDescEn: string }[];
    productConfig: { key: string; keyDesc: string; positionId: string; keyDescEn: string }[];
  }>({
    method: 'get',
    url: '/web/getProductConfig',
    params,
  });
}
export async function getMatchNumber() {
  return request<any>({
    method: 'get',
    url: '/web/match',
  });
}

// 全部已读
export async function handleReadAll() {
  return request<any>({
    method: 'get',
    url: '/web/readAll',
  });
}

// 获取订单
export async function getOrderDetail(id: string) {
  return request<any>({
    method: 'get',
    url: `/web/orderDetail/${id}`,
  });
}

// 下载
export async function handleDownloadImg(data: any, orderId: any) {
  return request<any>({
    method: 'post',
    url: `/web/download/${orderId}`,
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    responseType: 'blob',
  });
}

export async function handleGoodBtn(data: { productId: number; likeFlag: number }) {
  return request<[]>({
    method: 'post',
    url: '/web/sub',
    data,
  });
}
export async function disSubGoodBtn(data: { productId: number }) {
  return request<[]>({
    method: 'post',
    url: '/web/disSub',
    data,
  });
}

export async function handleSubReview(data: { productId: number; socre: number; content: string }) {
  return request<[]>({
    method: 'post',
    url: '/web/subReview',
    data,
  });
}

// 评论列表
export async function getListReview(params: { productId: string; page: number; size: number }) {
  return request<Center.Data<Center.ProductList[]>>({
    method: 'get',
    url: `/web/listReview`,
    params,
  });
}

export async function getListByMerchantId(params: { merchantId: string }) {
  return request<Center.ProductList[]>({
    method: 'get',
    url: '/web/listByMerchantId',
    params,
  });
}
export async function handleDeleteReview(data: { id: string }) {
  return request<[]>({
    method: 'post',
    url: '/web/delReview',
    data,
  });
}
export async function handleCalculate(data: {
  loanAmount: number;
  loanTerm: number;
  rate: number;
}) {
  return request<any>({
    method: 'post',
    url: '/web/calculate',
    data,
  });
}
